//
//  LGGroupChatMemberCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/27.
//

#import "LGGroupChatMemberCell.h"

@interface LGGroupChatMemberCell()
/**   */
@property (nonatomic , strong)UIImageView *headView;
/**   */
@property (nonatomic , strong)UILabel *typeLabel;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;

@end

@implementation LGGroupChatMemberCell


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.nameLabel.text = LGNSString(dataDic[@"realname"]);
    UIImage *placeHolder = nil;
    if([dataDic.allKeys containsObject:@"patient_id"]){
        //患者
        self.typeLabel.hidden = NO;
        self.typeLabel.text = @"患者";
        self.typeLabel.textColor = [UIColor colorWithString:@"#8F7EF9"];
        self.typeLabel.backgroundColor = [UIColor colorWithString:@"#DFDAFF"];
        
        placeHolder = [dataDic[@"gender"] isEqualToString:@"男"]?defaultPatientMan:defaultPatientWomen;
        
    }else{
        //医生
        if([dataDic[@"is_leader"] integerValue] == 1){
            //队长
            self.typeLabel.hidden = NO;
            self.typeLabel.text = @"队长";
            self.typeLabel.textColor = [UIColor colorWithString:@"#FFFFFF"];
            self.typeLabel.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0.5];
            
        }else if ([dataDic[@"is_manage"] integerValue] == 1){
            //管理员
            self.typeLabel.hidden = NO;
            self.typeLabel.text = @"管理员";
            self.typeLabel.textColor = [UIColor colorWithString:@"#FFFFFF"];
            self.typeLabel.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0.5];
            
        }else{
            self.typeLabel.hidden = YES;
        }
        placeHolder = ([dataDic[@"role_type"] integerValue]==10)?defaultDoctorPic:defaultNursePic;
    }
    [self.headView sd_setImageWithURL:[NSURL URLWithString:LGNSString(dataDic[@"avatar_url"])] placeholderImage:placeHolder];
}


-(void)createSubView{
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.headView];
    [self.headView addSubview:self.typeLabel];
    [self.contentView addSubview:self.nameLabel];
    [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(5));
        make.centerX.equalTo(self.contentView);
        make.width.height.equalTo(@(viewPix(50)));
    }];
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.headView);
        make.height.equalTo(@(viewPix(17)));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headView.mas_bottom).offset(viewPix(5));
        make.left.equalTo(self.contentView).offset(3);
        make.right.equalTo(self.contentView).offset(-3);
    }];
}

-(UIImageView *)headView{
    if(!_headView){
        _headView = [[UIImageView alloc]init];
        _headView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
        _headView.userInteractionEnabled = YES;
        _headView.cornerRidus = 5;
    }
    return _headView;
}


-(UILabel *)typeLabel{
    if(!_typeLabel){
        _typeLabel = [UILabel lableWithText:@"" colorString:@"#FFFFFF" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _typeLabel;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _nameLabel;
}

@end
